﻿using HKSdkLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Ozone.Views.Video
{
    /// <summary>
    /// BackVideoWindow.xaml 的交互逻辑
    /// </summary>
    public partial class BackVideoWindow : Window
    {
        private System.Windows.Forms.Timer timerPlayback;
        private HKCam hK;

        public BackVideoWindow()
        {
            InitializeComponent();
        }

        public BackVideoWindow(int userID, HKCam hKCam)
        {
            InitializeComponent();
            timerPlayback = new System.Windows.Forms.Timer();
            hK = hKCam;
        }

        private void BackVideoWindow_Loaded(object sender, RoutedEventArgs e)
        {
            dtBegin.Text = Convert.ToDateTime(DateTime.Now.ToString("D").ToString()).ToString();//初始化成当天的0点
            dtEnd.Text = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("D").ToString()).AddSeconds(-1).ToString();  //初始化成当天的23:59:59
        }

        private void btnVideo_Click(object sender, RoutedEventArgs e)
        {
            string tag = ((Button)sender).Tag.ToString();
            switch (tag)
            {
                case "backvideo":
                    hK.hKSdkMethods.ViewPlaybackVideo(1, this.pageVideo.pictureBox, DateTime.Parse(dtBegin.Text), DateTime.Parse(dtEnd.Text), hK.m_userID, out hK.ErrorMessage); //查看回放
                    timerPlayback.Interval = 1000;
                    timerPlayback.Enabled = true;
                    break;
                case "pausevideo":
                    string sContent = ((Button)sender).Content.ToString();
                    if (sContent == "暂停")
                        ((Button)sender).Content = "播放";
                    else
                        ((Button)sender).Content = "暂停";
                    hK.hKSdkMethods.ViewPausePlaybackVideo(out hK.ErrorMessage);//暂停回放
                    break;

                case "fastvideo":
                    hK.hKSdkMethods.ViewFastPlaybackVideo(out hK.ErrorMessage);//快放回放
                    break;

                case "slowvideo":
                    hK.hKSdkMethods.ViewSlowPlaybackVideo(out hK.ErrorMessage); //慢放回放
                    break;

                default:
                    break;
            }
        }
    }
}